package com.dong.ui.component.home;

import com.dong.common.constant.PropertiesConst;
import com.dong.common.view.CommonView;
import com.dong.ui.component.IconPanel;
import com.dong.ui.constant.IconConst;
import com.dong.ui.util.IconUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.Map;

/**
 * @description:
 * @author: 陈瑞东
 * @create: 2021-08-27 09:32
 */
public class TopPanel extends JPanel implements CommonView {

    /*==================组件==================*/
    // 上方图标
    IconPanel foodListIcon;
    IconPanel addNewIcon;


    /*==================组件==================*/
    /*==================参数==================*/


    /*==================参数==================*/
    /*==================标志==================*/

    /*==================标志==================*/

    public TopPanel() {
        init(null);
    }

    public TopPanel(LayoutManager layout) {
        super(layout);
        init(null);
    }

    @Override
    public void init(Map<String, Object> params) {

        handleView();

        // 设置大小
        setSize(new Dimension(WIDTH, HEIGHT));

        // 设置可见
        setVisible(true);

        handleAction();
    }

    @Override
    public void initComponent() {
        // 设置子组件
        foodListIcon = new IconPanel(IconConst.ICON_FOODLIST, IconUtils.getHomeTopIcon(PropertiesConst.ICON_KEY_FOODLIST));
        addNewIcon = new IconPanel(IconConst.ICON_ADDNEW, IconUtils.getHomeTopIcon(PropertiesConst.ICON_KEY_ADDNEW));
    }

    @Override
    public void initParams() {

    }

    @Override
    public void handleView() {
        initParams();
        initComponent();

        // 顶部容器——用于隔开顶部距离
        Box topVBox = Box.createVerticalBox();
        // 顶部容器——包含控件
        JPanel topBox = new JPanel(new FlowLayout(FlowLayout.LEFT));

        topBox.add(foodListIcon);
        topBox.add(addNewIcon);

        topVBox.add(Box.createVerticalStrut(1));
        topVBox.add(topBox);
//        topVBox.add(Box.createVerticalStrut(20));
        this.add(topVBox);

    }

    @Override
    public void handleAction() {

    }

    /**
     * 给子组件鼠标添加事件
     * @param l
     */
    public void addCompomentMouseListener(MouseListener l) {
        foodListIcon.addMouseListener(l);
        addNewIcon.addMouseListener(l);
    }
}
